/********************* WHIRLPOOL *********************/
//  Depends: model.js
//  Depends: database-localstorage.js
//
// Reference: http://forums.whirlpool.net.au/forum-replies.cfm?t=1220737

function Whirlpool() {
	this.options = {};
	this.options.wpKey = '';
	this.options.wpUrl = 'http://whirlpool.net.au/api/';
	//this.options.wpWatchedUrl = 'http://forums.whirlpool.net.au/forum-replies.cfm?t={{:ID}}&p={{:LASTPAGE}}&#r{{LASTREAD}}';
}

// Constructor
//Whirlpool.prototype.constructor = ApplicationSettings();

Whirlpool.prototype.init = function(options){
	//this.load();
	this.options = $.extend({}, this.options, options);
}
  
  
Whirlpool.prototype.getWatched = function() {
	var deferred = $.Deferred();
	// Using jQuery-jsonp rather than the .ajax library built into jQuery as it handles errors better (or at all...)
	$.jsonp({
		url: this.options.wpUrl,
		timeout : 10000,
        data: {
			"key": this.options.wpKey,
			"get": "watched",
			"output": "json",
			"watchedmode": "0"	// 0 = Unread, 1 = All
        },
		jsonp: 'jsonp',	// Not used by jQuery-jsonp, left in case wish to switch back to jQuery.ajax
		callback: 'jsonp',	// Used by jQuery-jsonp as alt. to 'jsonp' switch above
		callbackParameter: 'jsonp', // Used by jQuery-jsonp
        dataType: 'jsonp',
        success: function(json, textStatus) {
			deferred.resolve(json);
        },
        error: function(xOptions, textStatus) {
			deferred.reject(xxOptions, textStatus);
        },
		complete: function(data) {
			alert('complete');
		}
	});
	return deferred.promise();
}
  
